<?php TPL::output('global/header_meta.tpl.htm'); ?>

<div class="aw-register-box">
    <div class="mod-head">
        <a href=""><img style="width:30%;height:30%;" src="<?php echo G_STATIC_URL; ?>/css/<?php echo $this->template_name; ?>/img/res_logo.png" alt="" /></a>
    </div>
    <div class="mod-body">
        <form class="aw-register-form"  method="post" id="register_form">
            <?php if ($this->icode) { ?><input type="hidden" name="icode" id="icode" value="<?php echo $this->icode; ?>" /><?php } ?>
            <?php if ($_GET['yoyow']) { $_GET['yoyow'];?><input type="hidden" name="yoyow"  value="<?php echo $_GET['yoyow']; ?>" /><?php } ?>
            <?php if ($this->return_url) { ?><input type="hidden" name="return_url" value="<?php echo $this->return_url; ?>" /><?php } ?>
            <ul>
                <li class="alert alert-danger collapse error_message text-left">
                    <i class="icon icon-delete"></i> <em></em>
                </li>
                <li>
                    <input class="aw-register-name form-control" type="text" name="user_name" placeholder="<?php _e('用户名'); ?>" tips="<?php _e('请输入一个 6-14 位的用户名');?>" errortips="<?php _e('用户名长度不符合');?>" value="" />
                </li>
                <!-- <li>
                     <input class="aw-register-email form-control" type="text" placeholder="<?php _e('邮箱'); ?>" name="email" tips="<?php _e('请输入你常用的电子邮箱作为你的账号'); ?>" value="<?php echo htmlspecialchars($_GET['email']); ?>"  errortips="<?php _e('邮箱格式不正确'); ?>" />
                 </li>-->
                <li>
                    <input class="aw-register-mobile form-control" type="text" placeholder="<?php _e('手机'); ?>" name="mobile" tips="<?php _e('请输入你正在使用的手机号'); ?>" id='phone' value="<?php echo htmlspecialchars($_GET['mobile']); ?>"  errortips="<?php _e('手机号不正确'); ?>" />
                </li>
                <li>
                    <input class="aw-register-smsflag form-control" type="text"  name="smsflag"  value=""  style="display:none" />
                </li>
               <!-- <li class="aw-register-verify">
                    <img class="pull-right" id="captcha" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" src="">
                    <input type="text" class="form-control" name="seccode_verify" placeholder="<?php _e('验证码'); ?>" />
                </li>-->
                <li class="aw-register-verify">
                    <div id="embed-captcha"></div>
                    <p id="wait" class="show">正在加载验证码......</p>
                    <p id="notice" class="hide">请先完成验证</p>
                </li>
                <li>
                    <input class="aw-register-validate form-control" id="smscode" style="width:56%;float:left;" type="text" placeholder="<?php _e('短信验证码'); ?>" name="smscode" tips="<?php _e('请输入短信验证码'); ?>" errortips="<?php _e('短信验证码不正确'); ?>" />
                    <button style="width: 31%;pointer-events:initial; cursor:pointer;display:inline;font-size: 12px;margin: 0 0 2px 15px;height: 40px;" id="Smsbtn" type="button"  class="btn btn-large btn-blue btn-block">获取短信验证码</button>
                </li>
                <li>
                    <input class="aw-register-inviteCode form-control" type="text" placeholder="<?php _e('邀请码(非必填)'); ?>" name="inviteCode" tips="<?php _e('邀请码属于非必填项'); ?>" value="<?php if($this->inviteCode){?><?php echo $this->inviteCode; ?><?php }?>"  errortips="<?php _e('邀请码不存在'); ?>" />
                </li>
                <li>
                    <label class="oldPwdTip password-label" onclick="$(this).hide();$('#password').focus();" style="display: block;margin-left: 15px;"><?php _e('密码'); ?></label>
                    <input class="aw-register-pwd form-control" type="password" name="password" id="password" tips="<?php _e('请输入 6-16 个字符,区分大小写'); ?>" errortips="<?php _e('密码不符合规则'); ?>" onfocus="hideOldPwdTip('password');" onblur="toggleOldPwdTip('password',this.value);"/>
                </li>
                <li class="more-information collapse">
                    <ul>
                        <li>
                            <?php _e('性别'); ?>:
                            <label>
                                <input name="sex"  value="1" type="radio" /> <?php _e('男'); ?>
                            </label>&nbsp;
                            <label>
                                <input name="sex"  value="2" type="radio" /> <?php _e('女'); ?> </label>&nbsp;
                            <label>
                                <input name="sex"  value="3" type="radio" checked="checked" /> <?php _e('保密'); ?>
                            </label>
                        </li>
                        <li>
                            <?php _e('职业'); ?>:
                            <select name="job_id">
                                <option value="">--</option>
                                <?php echo H::display_options($this->job_list); ?>
                            </select>
                        </li>
                        <li>
                            <?php _e('所在城市'); ?>:
                            <select name="province" class="select_area" style="display:inline-block"></select>

                            <select name="city" class="select_area"></select>
                        </li>
                        <li>
                            <input type="text" class="form-control" placeholder="<?php _e('一句话介绍'); ?>" id="welcome_signature" value="<?php if ($this->user_info['signature']) { echo $this->user_info['signature']; } ?>" name="signature" />
                        </li>
                    </ul>
                </li>
                <li>
                    <hr />
                    <a class="more-information-btn"><?php _e('更多资料'); ?></a>
                </li>

                <li class="last">
                    <label><input type="checkbox" checked="checked" value="agree" name="agreement_chk" /> <?php _e('我同意'); ?></label> <a href="javascript:;" class="aw-agreement-btn"><?php _e('用户协议'); ?></a>
                    <a href="account/login/" class="pull-right">已有账号?</a>
                    <div class="aw-register-agreement collapse">
                        <div class="aw-register-agreement-txt" id="register_agreement"></div>
                    </div>

                </li>
                <li class="clearfix">
                    <button class="btn btn-large btn-blue btn-block" id="saveregister" ><?php _e('注册'); ?></button>
                </li>
            </ul>
        </form>
    </div>
    <div class="mod-footer"></div>
</div>

<style>
    .show {
        display: block;
    }
    .hide {
        display: none;
    }
    #notice {
        color: red;
    }
    #embed-captcha span {
        position: static;
    }
</style>
<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/slide_captcha/gt.js"></script>
<script type="text/javascript">
    $(document).ready(function ()
    {
        $.get(G_BASE_URL + '/account/ajax/register_agreement/', function (result) { $('#register_agreement').html(result.err); }, 'json');

        $('.aw-agreement-btn').click(function()
        {
            if ($('.aw-register-agreement').is(':visible'))
            {
                $('.aw-register-agreement').hide();
            }
            else
            {
                $('.aw-register-agreement').show();
            }
        });

        $('.more-information-btn').click(function()
        {
            $('.more-information').fadeIn();
            $(this).parent().hide();
        });

        verify_register_form('#register_form');

        /* 注册页面验证 */
        function verify_register_form(element)
        {
            $(element).find('[type=text], [type=password]').on({
                focus : function()
                {
                    if (typeof $(this).attr('tips') != 'undefined' && $(this).attr('tips') != '')
                    {
                        $(this).parent().append('<span class="aw-reg-tips">' + $(this).attr('tips') + '</span>');
                    }
                },
                blur : function()
                {
                    if ($(this).attr('tips') != '')
                    {
                        switch ($(this).attr('name'))
                        {
                            /* case 'user_name' :
                                var _this = $(this);
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 2)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $.post(G_BASE_URL + '/account/ajax/check_username/',
                                        {
                                            username: $(this).val()
                                        }, function (result)
                                    {
                                        if (result.errno == -1)
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + result.err + '</span>');
                                        }
                                        else
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                        }
                                    }, 'json');
                                }
                                return;*/

                            /* case 'email' :
                                 $(this).parent().find('.aw-reg-tips').detach();
                                 var emailreg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                                 if (!emailreg.test($(this).val()))
                                 {
                                     $(this).parent().find('.aw-reg-tips').detach();
                                     $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                     return;
                                 }
                                 else
                                 {
                                     $(this).parent().find('.aw-reg-tips').detach();
                                     $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                 }
                                 return;*/
                            case 'mobile':
                                $(this).parent().find('.aw-reg-tips').detach();
                                var phonereg = /^1[345789]\d{9}$/;
                                if (!phonereg.test($(this).val()))
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');

                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');

                                }
                                return;
                            case 'password' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 6)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                }
                                return;

                        }
                    }

                }
            });
        }

        $('.select_area').LocationSelect({
            labels: ["<?php _e('请选择省份或直辖市'); ?>", "<?php _e('请选择城市'); ?>"],
            elements: document.getElementsByTagName("select"),
            detector: function () {
                this.select(["<?php echo $this->user_info['province']; ?>", "<?php echo $this->user_info['city']; ?>"]);
            },
            dataUrl: G_BASE_URL.replace('/?', '') + '/static/js/areas.js'
        });

        /*仿刷新：检测是否存在cookie*/
        if($.cookie("captcha")){
            var count = $.cookie("captcha");
            var btn = $('#Smsbtn');
            $('#Smsbtn').prop('disabled', true);
            btn.text(count+'秒后可重新获取')
            var resend = setInterval(function(){
                count--;
                if (count > 0){
                    btn.text(count+'秒后可重新获取')
                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                }else {
                    $('#Smsbtn').prop('disabled', false);
                    clearInterval(resend);
                    btn.text("获取短信验证码")
                }
            }, 1000);
        }

        var photoflag=0;


        $('#saveregister').click(function(){
            $('#register_form').attr('action',G_BASE_URL+'/account/ajax/register_process/');
            AWS.loading('show');
            AWS.ajax_post($('#register_form'), AWS.ajax_processer, 'error_message'); return false;
        })


        var handlerEmbed = function (captchaObj) {
            $("#Smsbtn").click(function (e) {
                var phonereg = /^1[3456789]\d{9}$/;
                var mobile = $('input[name="mobile"]').val();
                var seccode_verify=$('input[name="seccode_verify"]').val();
                var register_verify_code = '<?php echo get_setting('register_seccode'); ?>';

                if(mobile=='' ){
                    AWS.alert("请输入手机号");
                    return false;
                }
                if(!phonereg.test(mobile)){
                    AWS.alert("手机号格式不正确");
                    return false;
                }
                if($('#Smsbtn').text()!="获取短信验证码"){
                    return false;
                }

                var validate = captchaObj.getValidate();
                if (!validate) {
                    AWS.alert("请先完成验证");
                    return false;
                } else{
                    $.post(G_BASE_URL + '/account/ajax/check_mobile/',
                        {
                            mobile:mobile
                        }, function (result)
                        {
                            if (result.errno == -1)
                            {
                                AWS.alert("手机号已经注册！");
                                captchaObj.reset();
                                return false;
                            }else{
                                var count = 60;
                                var inl = setInterval(function () {
                                    $('#Smsbtn').prop('disabled', true);
                                    count -= 1;
                                    var text = count + ' 秒后可重新获取';
                                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                                    $('#Smsbtn').text(text);
                                    if (count <= 0) {
                                        clearInterval(inl);
                                        $('#Smsbtn').prop('disabled', false);
                                        $('#Smsbtn').text('获取短信验证码');
                                    }
                                }, 1000);
                                $('input[name="smsflag"]').val('0');

                                $.post(G_BASE_URL + '/account/ajax/send_mobile/',
                                    {
                                        mobile:mobile,
                                        geetest_challenge: validate.geetest_challenge,
                                        geetest_validate: validate.geetest_validate,
                                        geetest_seccode: validate.geetest_seccode,
                                        client_type: 'web',
                                        genre: '1'
                                    }, function (result)
                                    {
                                        if (result.errno == -1)
                                        {
                                            AWS.alert("短信发送成功，请注意查收");
                                            return false;
                                        }else{
                                            AWS.alert(result.err);
                                            return false;
                                        }
                                    }, 'json');
                            }
                        }, 'json');
                }


            });
            // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
            captchaObj.appendTo("#embed-captcha");
            captchaObj.onReady(function () {
                $("#wait")[0].className = "hide";
            });
        };
        $.ajax({
            // 获取id，challenge，success（是否启用failback）
            url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
            type: "get",
            dataType: "json",
            success: function (data) {
                var dataObj = eval('(' + data.rsm + ')');
                // 使用initGeetest接口
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                initGeetest({
                    gt: dataObj.gt,
                    challenge: dataObj.challenge,
                    new_captcha: dataObj.new_captcha,
                    offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    width: '100%' // 设置按钮宽度, 与父元素宽度一致
                }, handlerEmbed);
            }
        });
    });
</script>
<?php TPL::output('global/footer.tpl.htm'); ?>
